package com.amumu.netctoss.action;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import org.apache.commons.io.IOUtils;
import org.apache.struts2.ServletActionContext;

public class UploadAction {
	private File file;
	private String fileFileName;
	public void setFile(File file) {
		this.file = file;
	}
	public void setFileFileName(String fileFileName) {
		this.fileFileName = fileFileName;
	}
	
	public String execute(){
		System.out.println("file:"+file);
		System.out.println("name:"+file.getName()+","+fileFileName);
		try {
			String path = ServletActionContext.getServletContext().getRealPath("upload");
			BufferedInputStream is = new BufferedInputStream(new FileInputStream(file));
			BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(new File(path+"/"+fileFileName)));
			
			IOUtils.copy(is, os);
			is.close();
			os.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
}
